using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;

// ReSharper disable CheckNamespace
namespace System.Windows.Controls
// ReSharper restore CheckNamespace
{
    /// <summary>
    /// Sample event handler:  
    /// private void ButtonClick(object sender, RoutedEventArgs e) {}
    /// Adorners must subclass the abstract base class Adorner.
    /// </summary>
    public class SimpleCircleAdorner : Adorner
    {
        /// <summary>
        /// Be sure to call the base class constructor.
        /// </summary>
        /// <param name="adornedElement"></param>
        public SimpleCircleAdorner(UIElement adornedElement)
            : base(adornedElement)
        {
        }
        
        /// <summary>
        /// When overridden in a derived class, participates in rendering operations that are directed by the layout system. The rendering instructions for this element are not used directly when this method is invoked, and are instead preserved for later asynchronous use by layout and drawing.
        /// A common way to implement an adorner's rendering behavior is to override the OnRender
        /// method, which is called by the layout system as part of a rendering pass.
        /// </summary>
        /// <param name="drawingContext">The drawing instructions for a specific element. This context is provided to the layout system.</param>
        protected override void OnRender(DrawingContext drawingContext)
        {
            var adornedElementRect = new Rect(this.AdornedElement.DesiredSize);

            // Some arbitrary drawing implements.
            var renderBrush = new SolidColorBrush(Colors.Green);
            renderBrush.Opacity = 0.2;
            Pen renderPen = new Pen(new SolidColorBrush(Colors.Navy), 1.5);
            const double renderRadius = 5.0;

            // Draw a circle at each corner.
            drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopLeft, renderRadius, renderRadius);
            drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopRight, renderRadius, renderRadius);
            drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomLeft, renderRadius, renderRadius);
            drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomRight, renderRadius, renderRadius);
        }
    }
}
